package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import service.UserService;
import service.impl.UserServiceImpl;

import entity.User;

public class UserAddServlet extends HttpServlet {


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.sendRedirect(request.getContextPath() + "/register.html");
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		String uname = request.getParameter("name");
		String upass = request.getParameter("pass");
		
		User user = new User();
		user.setName(uname);
		user.setPass(upass);
		
		UserService us = new UserServiceImpl();
		us.addUser(user);
		response.sendRedirect(request.getContextPath() + "/login.jsp");
	}

}
